﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TierService;
using TierApplication;

namespace OrderMgr.CustomerInfo
{
    public partial class frmCustomerList : TierService.frmTemplate
    {

        #region "Member Variables""
        public string _CustID="";
        public string _Name="";
        public string _IDCard="";
        public string _Birthday="";
        #endregion

        #region "FormCloseRetrunvalue"
        public delegate void ReturnValue(string str);
        public ReturnValue returnvalue;
        private void FormCloseReturnValue()
        {
            if (returnvalue != null)
            {
                returnvalue(_CustID);
            }
        }
        #endregion 

        public frmCustomerList()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string ls_where = "";

            if ((txtCustName.Text.Trim() != "") && (ckbCustName.Checked))
                ls_where = ls_where + " and CustName  like '%" + txtCustName.Text + "%'";

            if ((txtMobile.Text != "") && (ckbMobile.Checked))
                ls_where = ls_where + " and Mobile like '%" + txtMobile.Text + "%'";

            if ((txtContactAddress.Text != "") && (ckbContactAddress.Checked))
                ls_where = ls_where + " and ContactAddress like '%" + txtContactAddress.Text + "%'";

            if ((txtCustTypeID.Text.Trim() != "") && (ckbCustTypeID.Checked))
                ls_where = ls_where + " and CustTypeID = '" + (string)txtCustTypeID.EditValue + "'";

            if ((txtCustSource.Text.Trim() != "") && (ckbCustSource.Checked))
                ls_where = ls_where + " and CustSource = '" + (string)txtCustSource.EditValue + "'";

            DataSet dsPatient = T_Patient.GetList(ls_where);
            gcCustomer.DataSource = dsPatient.Tables[0];

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (gvCustomer.RowCount >= 1)
            {
                DataRow dr = gvCustomer.GetDataRow(gvCustomer.FocusedRowHandle);
                _CustID = dr["PatientID"].ToString();
                TierService.Utility.gPatientID = _CustID;
                TierService.Utility.gPatientName = dr["Name"].ToString();

                FormCloseReturnValue();
            }
            Close();
        }

        private void frmPatientList_Load(object sender, EventArgs e)
        {
            Utility.DataToLookupComboxEx(txtCustTypeID, C_DMB.GetListByType(C_DMB.DType.CustTypeID.ToString()), "CodeID", "CodeName");
            Utility.DataToLookupComboxEx(txtCustSource, C_DMB.GetListByType(C_DMB.DType.CustSource.ToString()), "CodeID", "CodeName");
    
            btnSearch.Focus();
            btnSearch_Click(this, null);
        }

        private void gvCustomer_DoubleClick(object sender, EventArgs e)
        {
            btnClose_Click(null, null);
        }




    }
}